package com.itlong.cloud.controller.parking;

import com.itlong.cloud.POJO.DTO.operate.ParkingRecordPageDTO;
import com.itlong.cloud.POJO.DTO.property.PropertyMonthCardPaymentRecordGetPageDTO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.property.PropertyMonthCardPaymentRecordGetPageVO;
import com.itlong.cloud.POJO.VO.property.PropertyTemporaryCarFeeRecordVO;
import com.itlong.cloud.annotation.AuthAccessRequired;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.enumerate.ecode.PropertyErrorCodeEnum;
import com.itlong.cloud.paymenthub.IPropertyParkingFeeRecordServiceClient;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.utils.network.http.HttpProtocolUtil;
import com.itlong.cloud.utils.page.Page;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * <desc>
 *      物业-智慧停车-停车缴费记录控制器.
 * </desc>
 *
 * @createDate 2018/11/5
 */
@RequestMapping("/parking")
@RestController
public class PropertyParkingFeeRecordController {

    private  static final Logger LOG = LoggerFactory.getLogger(PropertyParkingFeeRecordController.class);

    @Autowired
    IPropertyParkingFeeRecordServiceClient iPropertyParkingFeeRecordServiceClient;

    /**
     * <desc>
     *      临时车缴费记录分页查询
     * <desc/>
     *
     * @param feeRecordDTO 分页查询参数
     * @return 标准返回结果
     * @author Juguang.S
     * @createDate 2018/11/5
     */
    @ResponseBody
    @AuthAccessRequired
    @PostMapping(path = "/car/temporaryCarFeeRecord")
    public Object fixedCarFeeRecordPage(ParkingRecordPageDTO feeRecordDTO){
        try{
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            feeRecordDTO = HttpProtocolUtil.parseRequestParamToDTO(ParkingRecordPageDTO.class, request);
            if(feeRecordDTO == null){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            Page<PropertyTemporaryCarFeeRecordVO> page = iPropertyParkingFeeRecordServiceClient.getTemporaryCarFeeRecordPage(feeRecordDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),page);
        }catch (Exception e){
            throw new DataAccessException("【物业_智慧停车】获取临时车缴费分页查询列表失败",e);
        }
    }

    /**
     * <desc>
     *      月卡缴费记录分页查询
     * <desc/>
     *
     * @param propertyMonthCardPaymentRecordGetPageDTO 分页查询参数
     * @return 标准格式化返回结果
     * @author wangzhi
     * @createDate 2018/11/08
     */
    @ResponseBody
    @AuthAccessRequired
    @PostMapping(path = "/monthCardPayment/getRecordPage")
    public Object getMonthCardPaymentRecordPage(PropertyMonthCardPaymentRecordGetPageDTO propertyMonthCardPaymentRecordGetPageDTO){
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            propertyMonthCardPaymentRecordGetPageDTO = HttpProtocolUtil.parseRequestParamToDTO(PropertyMonthCardPaymentRecordGetPageDTO.class, request);
            if (propertyMonthCardPaymentRecordGetPageDTO == null) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            if (StringUtils.isBlank(propertyMonthCardPaymentRecordGetPageDTO.getProjectId())) {
                return new MessageVO(PropertyErrorCodeEnum.PUB_PROJECT_ID_EMPTY_ERR.getErrorCode());
            }
            Page<PropertyMonthCardPaymentRecordGetPageVO> page = iPropertyParkingFeeRecordServiceClient.getMonthCardPaymentRecordPage(propertyMonthCardPaymentRecordGetPageDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),page);
        } catch (Exception e) {
            throw new DataAccessException("【物业_智慧停车】获取月卡缴费记录分页查询列表失败",e);
        }
    }
}